import lightgbm as lgb
import pandas as pd
import numpy as np
from datetime import datetime
import argparse

def train(datapath,isretrain,method=0):
    if(isretrain!=True):
        pass
    data=pd.read_csv(datapath)
    allcol=list(data.columns)
    allcol.remove('sample_id')
    data.drop_duplicates(subset=allcol,keep='first',inplace=True)

    featurelist=list(data.columns)
    featurelist.remove('sample_id')
    featurelist.remove('feature100')
    featurelist.remove('feature57')
    featurelist.remove('feature77')
    featurelist.remove('feature64')
    featurelist.remove('feature92')
    featurelist.remove('label')
    label='label'


    lgb_train = lgb.Dataset(data[featurelist], data[label])
    params = {
        'boosting_type': 'gbdt', 
        'num_class':6,
        'objective': 'multiclass', 
        'learning_rate': 0.01,
        'feature_fraction':0.9,
        'feature_fraction_seed':1,
        'seed':2023,  
        'verbose': -1
    }
    gbm = lgb.train(params, lgb_train, num_boost_round=1000)
    timestr=str(datetime.now())
    timestr=timestr.replace(' ','_')
    timestr=timestr.replace(':','-')
    gbm.save_model('./model/'+'model_'+timestr+'.txt')

if __name__=='__main__':
    # train('./data/traindata.csv',True,0)
    
    parser = argparse.ArgumentParser()
    parser.add_argument("data_path",default='./data/traindata.csv',type=str)
    parser.add_argument("isretrain",default=1,type=bool)
    parser.add_argument("method",default=0,type=int)
    args = parser.parse_args()
    train(args.data_path,args.isretrain,args.method)

